﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Configuration;

namespace 会员卡管理系统
{
    public partial class HouseManage : UserControl
    {
        
        public HouseManage()
        {
            InitializeComponent();
        }
        Vipclass.tb_viphouseinfo tbHouse = new Vipclass.tb_viphouseinfo();
        Vipclass.tbVipHouseMenthod Housementhod = new Vipclass.tbVipHouseMenthod();

        private void HouseManage_Load(object sender, EventArgs e)
        {
            tbHouse= Housementhod.tbHousefoFill(lvHouse, imageList1);
            labHousenum.Text= tbHouse.Inthousenum.ToString();
            labHasnum.Text = tbHouse.Inthasuse.ToString(); ;
            labNouse.Text= tbHouse.Intnouse.ToString();
        }

        private void tbxReserch_TextChanged(object sender, EventArgs e)
        {
            Housementhod.tbHousefoFind(lvHouse, imageList1, tbxReserch.Text);
        }

        private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            tbHouse = Housementhod.tbHousefoFill(lvHouse, imageList1);
            labHousenum.Text = tbHouse.Inthousenum.ToString();
            labHasnum.Text = tbHouse.Inthasuse.ToString(); ;
            labNouse.Text = tbHouse.Intnouse.ToString();
        }

        private void lvHouse_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (this.lvHouse.SelectedItems.Count > 0)
                {
                    string strshow = lvHouse.SelectedItems[0].Text;
                    labhouseid.Text = strshow;
                    tbHouse = Housementhod.tbHousetoshow(strshow);
                    if (tbHouse.Bolhousestay.ToString() == "0")
                    {
                        labstay.Text = "未住";
                    }
                    else
                    {
                        labstay.Text = "已住";
                    }
                    if(labstay.Text=="已住")
                    {
                        lvHouse.SelectedItems[0].ImageIndex = 1;
                    }
                    else
                    {
                        lvHouse.SelectedItems[0].ImageIndex = 0;
                    }
                    labusetime.Text = tbHouse.Intusetime.ToString();
                    labhouseid.Text = strshow;
                    Housementhod.tbHouseRecordfoFill(lvRecord, strshow);
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
            }
            
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.lvHouse.SelectedItems.Count > 0)
            {
                string strshow = lvHouse.SelectedItems[0].Text;
                if(MessageBox.Show("是否删除房间" + strshow + "！", "提示",MessageBoxButtons.YesNo,MessageBoxIcon.Information)==DialogResult.Yes)
                {
                    if (Housementhod.tbhousefodel(strshow) == 1)
                    {
                        MessageBox.Show("删除成功！","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("未删除！","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    }
                }
                else
                {
                    return;
                }
                
            }
            else
            {
                MessageBox.Show("无法删除，未选中！", "提示");
                return;
            }
            tbHouse = Housementhod.tbHousefoFill(lvHouse, imageList1);
            labHousenum.Text = tbHouse.Inthousenum.ToString();
            labHasnum.Text = tbHouse.Inthasuse.ToString(); ;
            labNouse.Text = tbHouse.Intnouse.ToString();
        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void groupBox3_Enter(object sender, EventArgs e)
        {

        }

        private void btnDelHse_Click(object sender, EventArgs e)
        {
            if (this.lvHouse.SelectedItems.Count > 0)
            {
                string strshow = lvHouse.SelectedItems[0].Text;
                if (MessageBox.Show("是否删除房间"+strshow+"！", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    if (Housementhod.tbhousefodel(strshow) == 1)
                    {
                        MessageBox.Show("删除成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("未删除！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

            }
            else
            {
                MessageBox.Show("无法删除，未选中！", "提示");
                return;
            }
            tbHouse = Housementhod.tbHousefoFill(lvHouse, imageList1);
            labHousenum.Text = tbHouse.Inthousenum.ToString();
            labHasnum.Text = tbHouse.Inthasuse.ToString(); ;
            labNouse.Text = tbHouse.Intnouse.ToString();
        }

        private void btnAddHse_Click(object sender, EventArgs e)
        {
            AddNewHouse addhse = new AddNewHouse();
            if(addhse.ShowDialog()==DialogResult.OK)
            {
                tbHouse = Housementhod.tbHousefoFill(lvHouse, imageList1);
                labHousenum.Text = tbHouse.Inthousenum.ToString();
                labHasnum.Text = tbHouse.Inthasuse.ToString(); ;
                labNouse.Text = tbHouse.Intnouse.ToString();
            }
            else
            {
                tbHouse = Housementhod.tbHousefoFill(lvHouse, imageList1);
                labHousenum.Text = tbHouse.Inthousenum.ToString();
                labHasnum.Text = tbHouse.Inthasuse.ToString(); ;
                labNouse.Text = tbHouse.Intnouse.ToString();
            }
        }
    }
}
